#include <iostream>
#include <vector>
#include <stack>

using namespace std;

int main()
{
	int n; cin >> n;
	vector<int> pushS(n), popS(n);
	for (auto& e : pushS) cin >> e;
	for (auto& e : popS) cin >> e;
	stack<int> s;
	int l = 0, r = 0;
	while (r < n) {
		if (s.empty() || s.top() != popS[r]) {
			s.push(pushS[l]);
			l++;
		}
		else {
			s.pop();
			r++;
		}
	}
	if (l == n) cout << "true";
	else cout << "false";

	return 0;
}